using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[CreateAssetMenu(fileName = "EnemyTargetInSkillRange-获得这个技能范围的敌方", menuName = "Skill/Target/EnemyTargetInSkillRange-获得在这个技能范围的敌方")]
public class EnemyInSkillRangeTarget : TargetSelectorBase
{
    public override List<Chess> SelectTargets(Chess chess ,GameEvent e)
    {
        var chessList = ChessManager.GetInstance().chessList;
        var enemyChess = chessList.Where(c => c.GetChessSide() != chess.GetChessSide()).ToList();
        var targetPositions =
            chess.GetChessSide() == ChessSide.Player1
                ? chess.chessDate.skillRange.rangeType == RangeType.Normal
                    ? Math.GetTargetPosition(chess.ChessDetail.Position,
                        chess.chessDate.skillRange.vector2IntMode)
                    : chess.chessDate.skillRange.vector2IntMode
                : chess.chessDate.skillRange.rangeType == RangeType.Normal
                    ? Math.GetEnemyTargetPosition(chess.ChessDetail.Position,
                        chess.chessDate.skillRange.vector2IntMode)
                    : chess.chessDate.skillRange.vector2IntMode;
        var targets = (from targetChess in enemyChess
            where targetPositions.Contains(targetChess.ChessDetail.Position)
            select targetChess).ToList();

        return targets;
    }
}